﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// Sine 角度旋转
/// </summary>
[AddComponentMenu("Behavior/SineRotate")]
public class BhvSineRotate : SineBase
{
    private Quaternion _saveRotation;
    public enum Axis
    {
        X,
        Y,
        Z,
    }

    public Axis rotateAxis = Axis.Z;

    protected override void AfterInit()
    {
        _saveRotation = this.transform.localRotation;
    }

    public void ResetState()
    {
        _saveRotation = this.transform.localRotation;
    }

    protected override void UpdateFromPhase(float value)
    {
        var waveRes = value;
        var quat = Quaternion.Euler(
            rotateAxis == Axis.X ? value : 0,
            rotateAxis == Axis.Y ? value : 0,
            rotateAxis == Axis.Z ? value : 0
            );

        this.transform.localRotation = quat * _saveRotation;


    }

}
